一、getSaveFileName 获取具体文件的路径阶
//BTN-Save Snap image
void suCam::on_pushButton_save_clicked()
{
//获取保存路径
if(snap_img.isNull())
return;
_TempPath = QCoreApplication::applicationDirPath();
//.exe项目文件所在目录
dtCurtime = QDateTime::currentDateTime(); //设置当前时间为保存时间
_TempPath = _TempPath + "//Image//" + dtCurtime.toString("yyyyMMddhhmmss");
//保存名称为path + image() + 日期年y月M日d时h分m秒s
strFileName = QFileDialog::getSaveFileName(this,tr("Save Picture"), //类函数QFileDiaLog:获取文件路径//getSaveFileName:获取保存文件名字
_TempPath,
"PNG(*.png);;JPG(*.jpg);;BMP(*.bmp);;TIF(*.tif)");
if(!strFileName.isNull())
{
int nIndex = strFileName.lastIndexOf('.');//寻找‘.’符号在字符串中的id
nIndex++;
int nLen = strFileName.length()-nIndex;
strSuffix = strFileName.right(nLen);//截取‘.’符号后面的字符串,这是为了获取用户选择的文件后缀名
snap_img.save(strFileName,strSuffix.toUpper().toUtf8(),100);//保存图片
}
}
二、getExistingDirectory 只选择到文件夹路径阶
QString directory = QFileDialog::getExistingDirectory(
this,
tr("选择文件夹"),
ADDRESS, //打开的路径
QFileDialog::ShowDirsOnly);
if (!directory.isEmpty())
{
fileDirLEdt->setText(directory);
qDebug() |